describe('TuneList.coffee', ->
  beforeEach ->
    # do nothing

  describe('TuneList class ', ->
    it 'constructs', ->
      target = new TuneList()

      expect(target.tunes.length).toEqual(0)

    it 'can add tune', ->
      target = new TuneList()
      file_stub1 =  jasmine.createSpy('FileStub')
      file_stub1.name = 'test1.mp3'
      tune1 = new Tune(file_stub1, 100)

      file_stub2 =  jasmine.createSpy('FileStub')
      file_stub2.name = 'test2.mp3'
      tune2 = new Tune(file_stub2, 200)

      target.add_tune(tune1)
      expect(target.tunes.length).toEqual(1)
      expect(target.tunes).toContain(tune1)

      target.add_tune(tune2)
      expect(target.tunes.length).toEqual(2)
      expect(target.tunes).toContain(tune1)
      expect(target.tunes).toContain(tune2)

    it 'can replace tune', ->
      target = new TuneList()

      file_stub1 =  jasmine.createSpy('FileStub')
      file_stub1.name = 'test1.mp3'
      tune1 = new Tune(file_stub1, 100)
      tune1.requester_session_id = 10

      file_stub2 =  jasmine.createSpy('FileStub')
      file_stub2.name = 'test1.mp3'
      tune2 = new Tune(file_stub2, 200)
      tune2.requester_session_id = 20

      file_stub3 =  jasmine.createSpy('FileStub')
      file_stub3.name = 'test2.mp3'
      tune3 = new Tune(file_stub3, 100)
      tune3.requester_session_id = 10

      file_stub4 =  jasmine.createSpy('FileStub')
      file_stub4.name = 'test1.mp3'
      replaced = new Tune(file_stub4, 100)
      replaced.requester_session_id = 30

      target.add_tune(tune1)
      target.add_tune(tune2)
      target.add_tune(tune3)
      target.search_and_replace(replaced)

      expect(target.tunes.length).toEqual(3)
      expect(target.tunes).toContain(tune1)
      expect(target.tunes).toContain(tune2)
      expect(target.tunes).toContain(tune3)

      expect(replaced.is_same_name_and_owner(tune1)).toBeTruthy()
      expect(replaced.requester_session_id).toEqual(tune1.requester_session_id)
  )
) 